package com.pine.start;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.Banner;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Pine Manage应用启动类
 *
 * @author pine manage
 * @since 2024-08-09
 */
@Slf4j
@MapperScan("com.pine.dao.*.mapper")
@EnableAspectJAutoProxy(exposeProxy = true)
@EnableCaching
@EnableTransactionManagement
@SpringBootApplication(scanBasePackages = {"com.pine"})
public class PineManageApplication {
    public static void main(String[] args) throws UnknownHostException {
        final ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(PineManageApplication.class)
                .bannerMode(Banner.Mode.LOG)
                .run(args);

        Environment env = applicationContext.getEnvironment();
        String contextPath = env.getProperty("server.servlet.context-path");
        log.info("""

                        ----------------------------------------------------------
                        \tApplication '{}' is running! Access URLs:
                        \tLocal: \t\thttp://localhost:{}{}
                        \tExternal: \thttp://{}:{}{}
                        \tDoc: \thttp://{}:{}{}/doc.html
                        \tActuator: \thttp://{}:{}{}/actuator
                        \tApi Url: \thttp://localhost:{}{}/v3/api-docs
                        \t----------------------------------------------------------
                        """,
                env.getProperty("spring.application.name"),
                env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                env.getProperty("server.port"), contextPath);
    }
}
